
const base_url="/gateway"

const post = function(url, data, callback) {
	uni.request({
		url: base_url + url,
		data: data,
		method: "POST",
		header: {
			'Content-type': 'application/x-www-form-urlencoded',
			Authorization: 'b45347ba145045de9240d961395fcbe0'
		},
		success: (res) => {
			if (res.statusCode === 200) {
				if(res.data.code === 401){
					uni.reLaunch({
					    // url: '/pages/my/login'
						
					});
				} else {
					callback(res.data)
				}
			} else {
				uni.showToast({
					title: '网络出错'
				});
				callback(res.data)
			}
		},
		fail: () => {
			// uni.hideLoading();
		},
		complete: () =>{
			// uni.hideLoading();	
		}
	});
}


const get = function(url, data, callback) {
	uni.request({
		url: base_url + url, 
		data: data,
		header: {
			'Content-type': 'application/x-www-form-urlencoded',
			Authorization: 'b45347ba145045de9240d961395fcbe0'
		},
		method: "GET",
		success: (res) => {
			if (res.statusCode === 200) {
				if(res.data.code === 401 || res.data.code === 400){
					uni.reLaunch({
					    // url: '/pages/my/login'
					});
				} else {
					callback(res.data)
				}
			} else {
				uni.showToast({
					title: '请求出错'
				})
				callback(res.data)
			}
		},
		fail: () => {
			// uni.hideLoading();
		},
		complete: () =>{
			// uni.hideLoading();	
		}
	});
}



export default {
	post,
	get
}
